package com.easy.service.Impl;

import com.easy.bean.Order_detail;
import com.easy.mapper.Order_detailMapper;
import com.easy.service.Order_detailService;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true) // 默认只读
public class Order_detailServiceImpl implements Order_detailService {

    @Autowired
    private Order_detailMapper order_detailMapper;

    @Override
    @Transactional(rollbackFor = Exception.class) // 写操作
    public Order_detail add(Order_detail order_detail) {
        order_detailMapper.add(order_detail);
        Order_detail result = order_detailMapper.one(order_detail.getDetail_id());
        return result;
    }

    @Override
    @Transactional(rollbackFor = Exception.class) // 写操作
    public int del(Integer id) {
        return order_detailMapper.del(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class) // 写操作
    public Order_detail edit(Order_detail order_detail) {
        order_detailMapper.edit(order_detail);
        Order_detail result= order_detailMapper.one(order_detail.getDetail_id());
        return result;
    }

    @Override
    @Transactional(rollbackFor = Exception.class) // 写操作
    public List<Order_detail> all(Order_detail order_detail) {
        return order_detailMapper.all(order_detail);
    }

    @Override
    @Transactional(rollbackFor = Exception.class) // 写操作
    public Order_detail one(Integer id) {
        return order_detailMapper.one(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class) // 写操作
    public void page(Page page, Order_detail order_detail) {

        int count=order_detailMapper.pageCount(order_detail);
        Object data=order_detailMapper.page(page,order_detail);
        page.setCount(count);
        page.setData(data);
    }
}
